<?php

namespace App\Admin\Controllers;

use App\Models\Order;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class OrderController extends AdminController
{
    protected $title = '订单';

    protected function grid()
    {
        $grid = new Grid(new Order);

        $grid->column('no','单号');
        $grid->column('user.name', '用户');
        $grid->column('message', '留言');
        $grid->column('order_time_date', '预约时间');
        $grid->column('points', '获取积分')->label('success');
        $grid->column('status', '状态')->display(function($value){
            return Order::$orderStatusMap[$value];
        })->label([
            1 => 'warning',
            2 => 'success',
            3 => 'danger',
        ]);
        $grid->column('address', '地址信息')->view('admin.order.address');
        $grid->column('created_at', '下单时间');

        return $grid;
    }

    protected function form()
    {
        $form = new Form(new Order);

        $form->text('no', __('No'));
        $form->number('user_id', __('User id'));
        $form->textarea('message', __('Message'));
        $form->number('order_time', __('Order time'));
        $form->text('address', __('Address'));
        $form->switch('closed', __('Closed'));
        $form->datetime('closed_at', __('Closed at'))->default(date('Y-m-d H:i:s'));
        $form->switch('completed', __('Completed'));
        $form->datetime('completed_at', __('Completed at'))->default(date('Y-m-d H:i:s'));

        return $form;
    }
}
